include(CheckCXXCompilerFlag)
function(make_lib_simd_runtime name)
    set(multiValueArgs SOURCES)
    cmake_parse_arguments(ARG "" "" "${multiValueArgs}" ${ARGN})

    add_library(${name}_sse_or_arm STATIC)
    target_sources(${name}_sse_or_arm PRIVATE ${ARG_SOURCES})

    add_library(${name}_avx STATIC)
    target_sources(${name}_avx PRIVATE ${ARG_SOURCES})
    target_compile_definitions(${name}_avx PRIVATE BYOD_COMPILING_WITH_AVX=1)
    if(WIN32)
        CHECK_CXX_COMPILER_FLAG("/arch:AVX" COMPILER_OPT_ARCH_AVX_SUPPORTED)
        if(COMPILER_OPT_ARCH_AVX_SUPPORTED)
            message(STATUS "Compiler supports flags: /arch:AVX")
            target_compile_options(${name}_avx PRIVATE /arch:AVX)
        else()
            message(STATUS "Compiler DOES NOT supports flags: /arch:AVX")
        endif()
    else()
        CHECK_CXX_COMPILER_FLAG("-mavx -mfma" COMPILER_OPT_ARCH_AVX_SUPPORTED)
        if(COMPILER_OPT_ARCH_AVX_SUPPORTED)
            message(STATUS "Compiler supports flags: -mavx -mfma")
            target_compile_options(${name}_avx PRIVATE -mavx -mfma -Wno-unused-command-line-argument)
        else()
            message(STATUS "Compiler DOES NOT supports flags: -mavx -mfma")
        endif()
    endif()

    add_library(${name} INTERFACE)
    target_link_libraries(${name} INTERFACE ${name}_sse_or_arm ${name}_avx)
endfunction()
